/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.client  
 */
package com.apache.client;

import java.util.Map;

import com.apache.api.vo.ResultEntity;
import com.apache.uct.common.ToolsUtil;

/**
 * description:  工作流系统特殊操作处理类
 * @author dwu 创建时间：2015-4-3  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class FlowCoreClient {

	private static String sysPass = ToolsUtil.getInstance().getClientValueByKey("push_to_dwusoft_pass");

	/**
	 * 根据权限Id，是否跨部门，部门id获取用户(actId,deptcross,deptId)
	 */
	public static String getUsersStr(Map<String, Object> map) {
		map.put("sysPass", sysPass);
		map.put("methodType", "getUsersStr");
		String result = "";
		ResultEntity root = UctProtoclClient.getInstance().doService("uctService", "flowCore", map);
		if (!ToolsUtil.isEmpty(root.getEntity())) {
			result = getXmlForUsers(root.getResult(), root.getMessage(), String.valueOf(root.getEntity()));
		} else {
			result = getXmlForUsers("false", root.getMessage(), "");
		}
		return result;
	}

	/**
	 * description:  远程根据系统获取该系统下的权限树(fatherId,actId)
	 */
	public static String getActTree(Map<String, Object> map) {
		map.put("sysPass", sysPass);
		map.put("methodType", "getActTree");
		String result = "";
		ResultEntity root = UctProtoclClient.getInstance().doService("uctService", "flowCore", map);
		if (!ToolsUtil.isEmpty(root.getEntity())) {
			result = getXmlForActTree(root.getResult(), root.getMessage(), String.valueOf(root.getEntity()));
		} else {
			result = getXmlForActTree("false", root.getMessage(), "");
		}
		return result;
	}

	private static String getXmlForUsers(String result, String errmsg, String users) {
		StringBuffer XmlStr = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><root>");
		XmlStr.append("<result>" + result + "</result><errmsg>" + errmsg + "</errmsg><users>" + users + "</users>");
		XmlStr.append("</root>");
		return XmlStr.toString();
	}

	private static String getXmlForActTree(String result, String errmsg, String jsonInfo) {
		StringBuffer XmlStr = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><root>");
		XmlStr.append("<result>" + result + "</result><errmsg>" + errmsg + "</errmsg><jsonInfo>" + jsonInfo
				+ "</jsonInfo>");
		XmlStr.append("</root>");
		return XmlStr.toString();
	}
}
